class Solution
{
public:
    bool canChange(string start, string target)
    {
        int n = start.size();
        int p1 = 0;
        int p2 = 0;
        while (true)
        {
            while (p1 < n && start[p1] == '_')
            {
                ++p1;
            }
            while (p2 < n && target[p2] == '_')
            {
                ++p2;
            }
            if (p1 == n || p2 == n)
            {
                break;
            }
            if (start[p1] != target[p2])
            {
                return false;
            }
            if (start[p1] == 'L' && p1 < p2)
            {
                return false;
            }
            if (start[p1] == 'R' && p1 > p2)
            {
                return false;
            }
            ++p1;
            ++p2;
        }
        return p1 == n && p2 == n;
    }
};